// main.qml
import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    width: 800
    height: 1200
    visible: true
    title: "新年倒计时"

    // 渐变背景
    Rectangle {
        anchors.fill: parent
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#2C3E50" }
            GradientStop { position: 0.5; color: "#34495E" }
            GradientStop { position: 1.0; color: "#2C3E50" }
        }

        // 闪烁的星星效果
        Repeater {
            model: 30
            Rectangle {
                width: Math.random() * 3 + 1
                height: width
                radius: width / 2
                color: "white"
                opacity: 0.3 + Math.random() * 0.7
                x: Math.random() * parent.width
                y: Math.random() * parent.height
                
                SequentialAnimation on opacity {
                    loops: Animation.Infinite
                    NumberAnimation { to: 0.2; duration: Math.random() * 2000 + 1000 }
                    NumberAnimation { to: 1.0; duration: Math.random() * 2000 + 1000 }
                }
            }
        }

        Column {
            anchors.centerIn: parent
            spacing: 40

            // 标题
            Text {
                id: titleText
                text: "🎊 新年倒计时 🎊"
                font.pixelSize: 60
                font.bold: true
                color: "#FFD700"
                anchors.horizontalCenter: parent.horizontalCenter
                
                SequentialAnimation on scale {
                    loops: Animation.Infinite
                    NumberAnimation { to: 1.1; duration: 1000; easing.type: Easing.InOutQuad }
                    NumberAnimation { to: 1.0; duration: 1000; easing.type: Easing.InOutQuad }
                }
            }

            // 年份显示
            Text {
                text: countdownTimer.targetYear
                font.pixelSize: 70
                font.bold: true
                color: "#FF6B6B"
                anchors.horizontalCenter: parent.horizontalCenter
            }

            // 倒计时数字区域
            Row {
                spacing: 20
                anchors.horizontalCenter: parent.horizontalCenter

                // 天数
                CountdownBlock {
                    label: "天"
                    value: countdownTimer.days
                }

                // 小时
                CountdownBlock {
                    label: "时"
                    value: countdownTimer.hours
                }

                // 分钟
                CountdownBlock {
                    label: "分"
                    value: countdownTimer.minutes
                }

                // 秒
                CountdownBlock {
                    label: "秒"
                    value: countdownTimer.seconds
                }
            }

            // 祝福语
            Text {
                text: countdownTimer.isNewYear ? "🎉 新年快乐！🎉" : "距离新年还有..."
                font.pixelSize: countdownTimer.isNewYear ? 45 : 35
                color: countdownTimer.isNewYear ? "#FFD700" : "#ECF0F1"
                anchors.horizontalCenter: parent.horizontalCenter
                opacity: 0.9
            }
        }
    }

    // 倒计时数字块组件
    component CountdownBlock: Rectangle {
        property string label: ""
        property string value: "00"
        
        width: 160
        height: 180
        radius: 15
        color: "#34495E"
        border.color: "#3498DB"
        border.width: 3
        
        // 添加阴影效果
        Rectangle {
            anchors.fill: parent
            anchors.margins: -5
            radius: parent.radius
            color: "transparent"
            border.color: "#3498DB"
            border.width: 1
            opacity: 0.3
            z: -1
        }
        
        Column {
            anchors.centerIn: parent
            spacing: 10
            
            // 数字
            Text {
                text: value
                font.pixelSize: 70
                font.bold: true
                color: "#ECF0F1"
                anchors.horizontalCenter: parent.horizontalCenter
                
                // 秒数变化时的动画效果
                Behavior on text {
                    SequentialAnimation {
                        NumberAnimation { 
                            target: parent
                            property: "scale"
                            to: 1.2
                            duration: 100
                        }
                        NumberAnimation { 
                            target: parent
                            property: "scale"
                            to: 1.0
                            duration: 100
                        }
                    }
                }
            }
            
            // 标签
            Text {
                text: label
                font.pixelSize: 28
                color: "#95A5A6"
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
    }
}